package DesignModeTest;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * CAS
 */
public class TestCAS {

  public static AtomicInteger count = new AtomicInteger(0);


  public static void main(String[] args) {

   for (int i = 0; i < 2; i++) {
      new Thread(new Runnable() {


        public void run() {
          try {
            Thread.sleep(10);
          } catch (InterruptedException e) {
            throw new RuntimeException(e);
          }
          for (int j = 0; j < 100; j++) {
            count.incrementAndGet();
          }
        }
      }).start();
    }
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
    System.out.println("count:" + count.get());

  }

}
